import { ajax, tools } from '../../js/ajax.js';

let txtName = document.getElementById('txtName');
let txtPwd = document.getElementById('txtPwd');
let txtPwd2 = document.getElementById('txtPwd2');
let txtNickname = document.getElementById('txtNickname');
let btnReg = document.getElementById('btnReg');
let spInfo = document.getElementById('spInfo');

btnReg.addEventListener('click', () => {
  spInfo.innerHTML = '';
  let user = {
    username: txtName.value,
    password: txtPwd.value,
    nickname: txtNickname.value,
  };
  // 密码的校验
  if (user.password.trim() == '') {
    spInfo.innerHTML = '密码不能为空';
    return;
  }
  if (txtPwd2.value != user.password) {
    spInfo.innerHTML = '密码不一致';
    return;
  }
  // 密码加密
  user.password = tools.md5(user.password);
  ajax.post('/user/auth/reg', user, (data) => {
    spInfo.innerHTML = data.message;
  });
});
